package com.gwnet.shop.controller.api;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.gwnet.common.mybatis.core.page.TableDataInfo;
import com.gwnet.shop.controller.MBaseController;
import com.gwnet.shop.domain.ShopGoods;
import com.gwnet.shop.service.IShopGoodsService;
import com.gwnet.shop.utils.AjaxResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 商品信息Controller
 * @author zhangwanpeng
 * @date 2024-07-19
 */
@RestController
@RequestMapping("/api/goods")
public class ShopGoodsApiController extends MBaseController
{
    @Resource
    private IShopGoodsService shopGoodsService;

    /**
     * 查询商品信息列表
     */
    @SaCheckPermission("shop:goods:list")
    @GetMapping("/list")
    public TableDataInfo list(ShopGoods shopGoods)
    {
        startPage();
        List<ShopGoods> list = shopGoodsService.selectShopGoodsList(shopGoods);
        return getDataTable(list);
    }

    /**
     * 获取商品信息详细信息
     */
    @SaCheckPermission("shop:goods:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shopGoodsService.selectShopGoodsById(id));
    }


    /**
     * 获取商品信息 及对应规格详细信息
     */
    @SaCheckPermission("shop:goods:query")
    @GetMapping(value = "/spec/{id}")
    public AjaxResult getSpecInfo(@PathVariable("id") Long id)
    {
        return success(shopGoodsService.selectShopGoodsSpecById(id));
    }

}
